<template>
	<scroll-view class="scrollbox" scroll-y>
		<imgEmpty v-if="orderList.length == 0"></imgEmpty>
		<view class="list" v-for="(item, idx) in orderList" :key="idx">
			<view class="title">{{ typeList[item.type] }}申请</view>
			<listItem :item="item" @workOrderAccept="workOrderAccept"></listItem>
		</view>
	</scroll-view>
</template>

<script>
import listItem from '../../components/listItem.vue';
import { waitAccept, workOrderAccept } from '../../api/order';
import imgEmpty from '@/components/imgEmpty.vue';
import { setTabBarBadge } from '@/utlis/other.js';
export default {
	components: { listItem, imgEmpty },
	data() {
		return {
			orderList: [],
			typeList: {
				1: '安装',
				2: '报修',
				3: '巡检',
				4: '续保',
				5: '校验',
				6: '验证',
				7: '培训',
				8: '移机'
			}
		};
	},
	created() {
		this.waitAccept();
	},
	onShow() {
		this.subscriptionsMsg();
		this.waitAccept();
	},
	methods: {
		workOrderAccept(orderid) {
			if (!orderid) {
				this.waitAccept();
				return;
			}
			workOrderAccept(orderid).then((data) => {
				uni.showToast({
					title: '接单成功',
					duration: 2000
				});
				this.waitAccept();
			});
		},
		waitAccept() {
			waitAccept().then((data) => {
				this.orderList = data.content;
				setTabBarBadge(this.orderList.length, true);
			});
		}
	}
};
</script>

<style lang="less" scoped>
.scrollbox {
	height: 100%;
	padding: 20upx;
	background-color: #f1f1f1;
	box-sizing: border-box;
	.list {
		padding: 20upx;
		.title {
			border-left: 6upx red solid;
			padding-left: 20upx;
			line-height: 1;
			font-size: 32upx;
			font-weight: 500;
			margin-bottom: 20upx;
		}
	}
}
</style>
